//
//  EmoticonManager.m
//  WLEmotionKeyBoard
//
//  Created by wanglei on 16/12/8.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "EmoticonManager.h"

@implementation EmoticonManager
- (instancetype)init{
    self = [super init];
    if(self){
        NSMutableArray <EmoticonPackages *>*packages = [[NSMutableArray alloc]init];
        self.packages = packages;
    [self loadEmotions];
    }
    return self;
}

//加载表情模型数组
- (void)loadEmotions{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"emoticons" ofType:@"plist" inDirectory:@"Emoticons.bundle"];
    if(path == nil){
        return;
    }
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *array = dict[@"packages"];
    if (array == nil) {
        return;
    }
    for (NSDictionary *item in array) {
        NSString *id = item[@"id"];
        [self loadGroupEmoticon:id];
    }
}

- (void)loadGroupEmoticon:(NSString *)id{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist" inDirectory:[NSString stringWithFormat:@"Emoticons.bundle/%@",id]];
    NSLog(@"id = %@,path = %@",id,path);
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSString *group_name_cn = dict[@"group_name_cn"];
//    NSLog(@"group_name_cn = %@",group_name_cn);
//    获得分组表情的字典类型数组
    NSArray *emoticons = dict[@"emoticons"];
//    实例化emoticons模型
    EmoticonPackages *p = [[EmoticonPackages alloc]initWithid:id name:group_name_cn array:emoticons];
    [self.packages addObject:p];
    NSLog(@"packages = %@",self.packages);
    
}
@end
